package com.zyk.scaffold.oauth.keypool.auth;

import com.alibaba.fastjson.JSON;
import com.zyk.scaffold.common.utils.jwt.Payload;
import com.zyk.scaffold.core.context.JwtHelper;
import com.zyk.scaffold.oauth.keypool.pojo.dto.KeyIdsContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class JwtKeyIdsHelper extends JwtHelper {
    public static KeyIdsContext getKeyIdsContext(String jwt) {
        Payload payload = getPayload(jwt);
        return JSON.parseObject(payload.getJson(), KeyIdsContext.class);
    }

    public static String toJwt(KeyIdsContext keyIdsContext){
        Payload payload = new Payload();
        payload.setJson(JSON.toJSONString(keyIdsContext));
        payload.setExpire(3L);
        return toJwt(payload);
    }

}
